/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package domain;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author yuyok
 */
@Entity(name = "VideoCategory")
@NamedQueries({
    @NamedQuery(name = "getVideoCategoryByName",
    query = "SELECT vc FROM VideoCategory vc WHERE vc.name = :name"),
    @NamedQuery(name = "getAllVideoCategories",
    query = "SELECT vc FROM VideoCategory vc")
})
public class VideoCategory extends DomainObject {

    private static final long serialVersionUID = 1L;
    @NotEmpty(message = "please, fill in category name")
    @Column(unique = true)
    private String name;
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "Video_to_category",
    joinColumns = {
        @JoinColumn(name = "category_id")},
    inverseJoinColumns = {
        @JoinColumn(name = "video_id")})
    private List<Video> videos = new ArrayList<Video>();

    public VideoCategory() {
    }

    public VideoCategory(String categoryName) {
        super();
        this.name = categoryName;
    }

    public List<Video> getVideos() {
        return this.videos;
    }

    public void addVideo(Video video) {
        this.videos.add(video);
    }

    public void setCategoryName(String categoryName) {
        this.name = categoryName;
    }

    public String getCategoryName() {
        return this.name;
    }
}
